package org.univie.mappr;

import java.util.ArrayList;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.util.Log;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

/**
 * Class for an overlay that contains a {@link FlickrPhoto}
 */
public class PhotoOverlay extends ItemizedOverlay {

	// debugging
	private static final String TAG = "org.univie.mappr.PhotoOverlay";
	
	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
	private Context mContext;

	public PhotoOverlay(Drawable defaultMarker, Context context) {
		super(boundCenterBottom(defaultMarker));
		mContext = context;
	}

	public void addOverlay(OverlayItem overlay) {
		mOverlays.add(overlay);
		populate();
	}

	@Override
	protected OverlayItem createItem(int arg0) {
		return mOverlays.get(arg0);
	}

	@Override
	public int size() {
		return mOverlays.size();
	}

	@Override
	protected boolean onTap(int index) {
		OverlayItem item = mOverlays.get(index);

		Log.d(TAG, "Item tapped! + " + item.getSnippet());
		
		FlickrPhoto photo = FlickrClient.getPhotoForId(item.getSnippet());
		MapprView.sCurrentPhoto = photo;
		
		// TODO Start fullscreen
		Intent intent = new Intent(mContext, FullscreenView.class);
		mContext.startActivity(intent);
		
		// FIXME: Show a dialog inbetween
//		AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
//
//		FlickrPhoto photo = FlickrClient.getPhotoForId(item.getSnippet());
//		MapprView.sCurrentPhoto = photo;
//
//		dialog.setTitle(photo.getTitle());
//		dialog.setIcon(photo.getThumbnailLocal());
//
//		String tags = "Tags:\n";
//		for (String tag : photo.getTags()) {
//			tags += tag + "\n";
//		}
//
//		dialog.setMessage("\n Owner: " + photo.getOwnerNsid() + "\n " + "Date:"
//				+ photo.getDateTaken().toGMTString() + "\n" + tags);
//
//		dialog.show();
		
		return true;
	}

}
